
using System;
using System.Configuration;

namespace TwitterFx
{
	public class TwitterFxConfig
	{
		public const string PROG_NAME = "TweetsFx";
		public const string ICONS_DIR = "icons";
		public const string CONFIG_FILE = "TweetsFx.config";
		
		public string dataPath { get; set; }
		public string iconsPath { get; set; }
	
		public static TwitterFxConfig twConfig = null;
		
		private Configuration config = null;
		
		public static TwitterFxConfig GetTwitterFxConfig()
		{
			if (twConfig == null)
			{
				twConfig = new TwitterFxConfig();
			}
			return twConfig;
		}
		
		private TwitterFxConfig()
		{
			dataPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), PROG_NAME);
			if (!System.IO.Directory.Exists(dataPath))
			{
				System.IO.Directory.CreateDirectory(dataPath);
			}
			
			iconsPath = System.IO.Path.Combine(dataPath, ICONS_DIR);
			if (!System.IO.Directory.Exists(iconsPath))
			{
				System.IO.Directory.CreateDirectory(iconsPath);
			}
			
			ExeConfigurationFileMap efm = new ExeConfigurationFileMap();
			efm.ExeConfigFilename = System.IO.Path.Combine(dataPath, CONFIG_FILE);
			config = ConfigurationManager.OpenMappedExeConfiguration(efm, ConfigurationUserLevel.None);
			
			config.AppSettings.Settings.Add(new KeyValueConfigurationElement("S", "DD"));
		}
		
		public void Save()
		{
			config.Save();
		}
		
		public int[] windowStatus
		{ 
			get 
			{
				int[] status = new int[4];

				if (config.AppSettings.Settings.Count > 1)
				{
					status[0] = Convert.ToInt32(config.AppSettings.Settings["Window.X"].Value);
					status[1] = Convert.ToInt32(config.AppSettings.Settings["Window.Y"].Value);
					status[2] = Convert.ToInt32(config.AppSettings.Settings["Window.Width"].Value);
					status[3] = Convert.ToInt32(config.AppSettings.Settings["Window.Hieght"].Value);
				}
				return status;
			}
			set
			{
				int[] status = value;
				config.AppSettings.Settings.Add(new KeyValueConfigurationElement("Window.X", status[0].ToString()));
				config.AppSettings.Settings.Add(new KeyValueConfigurationElement("Window.Y", status[1].ToString()));
				config.AppSettings.Settings.Add(new KeyValueConfigurationElement("Window.Width", status[2].ToString()));
				config.AppSettings.Settings.Add(new KeyValueConfigurationElement("Window.Hieght", status[3].ToString()));
				this.Save();
			}
		}
	}
}
